package com.wu.cloudribbonfeign.controller;

import com.wu.cloudribbonfeign.api.OrderApi;
import com.wu.cloudribbonfeign.api.UserApi;
import com.wu.common.entity.ResultData;
import io.seata.spring.annotation.GlobalTransactional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author whx
 * @date 2021/7/10
 */
@RestController
@RequestMapping("/order")
public class FeignController {

    @Autowired
    OrderApi orderApi;
    @Autowired
    UserApi userApi;

    @GetMapping("/list")
    public ResultData orderList(){
        return orderApi.orderList();
    }

    @PostMapping("/getById")
    public ResultData orderGetById(Integer id){
        return orderApi.orderGetById(id);
    }

    @PostMapping("/updateBoth")
    @GlobalTransactional(name = "update-both",rollbackFor = Exception.class)
    public ResultData updateBoth(int id){
        ResultData res2 = orderApi.orderUpdate(id);
        ResultData res1 = userApi.userUpdate(id);
        int i = 1/0;
        return res1;
    }

}
